package com.hardy.job;

import java.util.Stack;

/**
 * @author fuxiaohui3@nuoyuan.com.cn
 * @date 2018/11/21 10:34
 * 两个栈实现队列
 */
public class StackReverseQueue {
    Stack<Integer> s1 = new Stack<>();
    Stack<Integer> s2 = new Stack<>();

    public void push(Integer num){
        s1.push(num);
    }

    public Integer pop(){
        if(s2.empty()){
            while (!s1.empty()){
                Integer temp = s1.pop();
                s2.push(temp);
            }
        }
        return s2.pop();
    }

    public static void main(String[] args) {
        StackReverseQueue queue = new StackReverseQueue();
        queue.push(1);
        queue.push(2);
        queue.push(3);
        queue.push(4);
        queue.push(5);
        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());
        System.out.println(queue.pop());

        int res = 0;
        int n =1000;
        while (n!=0){
            n = n&n-1;
            res ++;
        }
        System.out.println(res);
        int res1=0;
        while (n!=0){
            res1+=n/5;
            n=n/5;
        }
        System.out.println(res1);
    }
}
